﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NHibernate;
using log4net;
using log4net.Config;
using System.IO;
namespace Ecreate.Data.Hibernate
{
    public class HibernateInstance : IFace.IHibernateService
    {
        public ISessionFactory getSessionFactory()
        {
            WebConfigAccess configAccess = new WebConfigAccess();
            IDictionary<string, string> dictionary = new System.Collections.Generic.Dictionary<string, string>();
            string hbmxml = System.Configuration.ConfigurationSettings.AppSettings["hbmxml"];
            string mappingAssembly = System.Configuration.ConfigurationSettings.AppSettings["MappingAssembly"];
            string popedomAssembly = System.Configuration.ConfigurationSettings.AppSettings["popedomAssembly"];
            dictionary.Add("connection.connection_string", configAccess.ConnectionString);
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            string hbmpath = Property.DataBaseConfigConfigHandler.getServerPath(hbmxml);
            config.Configure(hbmpath);
            config.AddAssembly(popedomAssembly);
            config.AddProperties(dictionary);
            if (mappingAssembly == null) throw new Exception("Not Found MappingAssembly");
            config.AddAssembly(mappingAssembly);
            return config.BuildSessionFactory();
        }
    }
}

